﻿using System;
using System.ComponentModel.Composition.Hosting;

namespace Shumisen.Core.Composition
{
	public class ContainerHolder
	{
		private static readonly Object sync = new object();

		private static volatile CompositionContainer _container;

		public static CompositionContainer Container
		{
			get
			{
				if (_container == null)
				{
					lock (sync)
					{
						if (_container == null)
						{
							// TODO 適切な例外
							throw new InvalidOperationException();
						}
						return _container;
					}
				}
				return _container;
			}
			set
			{
				Guard.ArgumentNotNull(value, "value");
				if (_container == null)
				{
					lock (sync)
					{
						if (_container == null)
						{
							_container = value;
						}
					}
				}
			}
		}
	}
}